<?php 
class faculty_Form_FrmFaculty extends Zend_Form
{
	public function frmFaculty($frm = null)
    {
    	$location = new Zend_Form_Element_Select('location');
    	$location->setAttribs(array(
    		'class'=>'form-control chzn-select validate[required]'
    	));
    	$db = new Application_Model_DbTable_DbGlobal();
    	$rs = $db->getLocation();
    	$opt = array(''=>'ជ្រើសរើស ខេត្ត ក្រុង/Choose Location');
    	foreach ($rs as $data){
    		$opt[$data["location_id"]] = $data["location_name"];
    	}
    	$location->setMultiOptions($opt);
    	
    	$dbBranch = new faculty_Model_DbTable_DbFaculty();
    	$rsBranch =$dbBranch->getAllBranch();
    	$optBranch = array(''=>'ជ្រើសរើស សាខា/Choose Branch');
    	foreach ($rsBranch as $dataBranch){
    		$optBranch[$dataBranch["branch_id"]] = $dataBranch["branch_name"];
    	}
    	$branch = new Zend_Form_Element_Select('branch');
    	$branch->setAttribs(array('class'=>'form-control chzn-select validate[required]'));
    	$branch->setMultiOptions($optBranch);
    	
//     	$dbBranch = new faculty_Model_DbTable_DbFaculty();
//     	$rsBranch =$dbBranch->getAllBranch();
//     	//$optBranch = array(''=>'ជ្រើសរើស សាខា/Choose Branch');
//     	foreach ($rsBranch as $dataBranch){
//     		$optBranch[$dataBranch["branch_id"]] = $dataBranch["branch_name"];
//     	}
//     	$branch = new Zend_Form_Element_Select('branch');
//     	$branch->setAttribs(array('class'=>'form-control' ,'id'=>"box1View", 'multiple'=>"multiple", 'size'=>"8"));
//     	$branch->setMultiOptions($optBranch);
    	
    	$branch_select = new Zend_Form_Element_Select('branch_select');
    	$branch_select->setAttribs(array('class'=>'form-control' ,'id'=>"box2View", 'multiple'=>"multiple", 'size'=>"8"));
    	
    	$faculty = new Zend_Form_Element_Text('faculty');
    	$faculty->setAttribs(array('class'=>'form-control validate[required]'));
    		
    	$status = new Zend_Form_Element_Select('status');
    	$status->setAttribs(array('class'=>'form-control validate[required]'));
    	$opt_status = array(''=>'ជ្រើសរើស ស្ថានភាព','1'=>'ប្រើប្រាស់','0'=>'មិនប្រើប្រាស់');
    	$status->setMultiOptions($opt_status);
    	
    	$description = new Zend_Form_Element_Textarea("description");
    	$description->setAttribs(array('class'=>'form-control'));
    		
    	$id = new Zend_Form_Element_Hidden('id');
    	$this->addElements(array($branch_select,$location,$branch,$status,$faculty,$description,$id));    	
    	if($frm){
    		$id->setValue($frm['faculty_id']);
    		$branch->setValue($frm["branch_id"]);
    		$faculty->setValue($frm["faculty_name"]);
    		$status->setValue($frm["status"]);
    		$description->setValue($frm["description"]);
//     		$db = new faculty_Model_DbTable_DbFaculty();
//     		$rs_branch = $db->getBranchNotInBF($frm['faculty_id']);
//     		if(!empty($rs_branch)){
//     			foreach ($rs_branch as $row_branch){
//     				$opt_branch[$row_branch["branch_id"]] = $row_branch["branch_name"];
//     			}
//     		}else $opt_branch = array();
//     		$branch->setMultiOptions($opt_branch);
    		
//     		$rs = $db->getBranchByFacID($frm['faculty_id']);
//     		foreach ($rs as $row){
//     			$option[$row["branch_id"]] = $row["branch_name"];
//     		}
//     		$branch_select->setMultiOptions($option);
    		
    	}
    	return $this;
     }
}
?>
